package com.monitor.model;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.tx.Tx;

@SuppressWarnings("serial")
public class Sensor extends Model<Sensor> {
	public static final Sensor sensor = new Sensor();
	private int id;
	private String name;
	private String position;

	/**
	 * 以物理地址查询 若没在数据库就返回0，若已经存在就直接返回该项的id
	 * 
	 * @param name
	 * @return
	 */
	public int findByName(String name) {
		long count = Db.queryLong("SELECT count(*) from sensor where name=?",name);
		if(count == 0){
			return 0;
		}
		
		return sensor.findFirst("select * from sensor where name=?", name)
				.getInt("id");

	}

	/**
	 * 查询sensor里所有的节点信息
	 * 
	 * @return List<Sensor>
	 */
	public List<Sensor> findAll() {
		return sensor.find("SELECT * FROM sensor");
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}
}
